<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions">


    <body>

        <ui:composition template="./Test.xhtml">



            <ui:define name="content">

                <h:commandButton value="Add New Events" action="AddEvent.xhtml" type="image" image="../resources/images/table/new_icon.png"></h:commandButton>
                <p:dataTable var="item" value="#{eventBean.listEvent}"
                             paginator="true" rows="10"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="5,10,15"
                             selection="selectedAU"
                             selectionMode="single">
                    <f:facet name="header">List all Events</f:facet>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Event Id"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.eventId}">
                        </h:outputText>
                    </p:column>
                    <p:column sortBy="#{item.category.categoryName}" filterBy="#{item.category.categoryName}" >
                        <f:facet name="header">
                            <h:outputText value="Category Name"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.category.categoryName}">
                        </h:outputText>
                    </p:column>
                    <c:set var="title" value="${item.eventTitle}"/>
                    <p:column sortBy="#{item.eventTitle}" filterBy="#{item.eventTitle}" >
                        <f:facet name="header">
                            <h:outputText value="Event Title"></h:outputText>
                        </f:facet>
                        <h:outputText value="${fn:substring(title,0,20)}">

                        </h:outputText>
                    </p:column>
                    <c:set var="info" value="${item.eventInfo}"/>
                    <p:column sortBy="#{item.eventInfo}" filterBy="#{item.eventInfo}" >
                        <f:facet name="header">
                            <h:outputText value="Event Info"></h:outputText>
                        </f:facet>
                        <h:outputText value="${fn:substring(info,0,20)}">

                        </h:outputText>
                    </p:column>
                    <c:set var="img" value="${item.eventImg}"/>
                    <p:column sortBy="#{item.eventImg}" filterBy="#{item.eventImg}" >
                        <f:facet name="header">
                            <h:outputText value="Event Image"></h:outputText>
                        </f:facet>
                        <h:outputText value="${fn:substring(img,0,20)}">

                        </h:outputText>
                    </p:column>

                    <p:column sortBy="#{item.releaseDate}" filterBy="#{item.releaseDate}" >
                        <f:facet name="header">
                            <h:outputText value="Event ReleaseDate"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.releaseDate}">
                            <f:convertDateTime pattern="MM/dd/yyyy" timeZone="VST"/>
                        </h:outputText>
                    </p:column>

                    <p:column sortBy="#{item.endDate}" filterBy="#{item.endDate}" >
                        <f:facet name="header">
                            <h:outputText value="Event EndDate"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.endDate}">
                            <f:convertDateTime pattern="MM/dd/yyyy" timeZone="VST"/>
                        </h:outputText>
                    </p:column>

                    <p:column sortBy="#{item.duration}" filterBy="#{item.duration}" >
                        <f:facet name="header">
                            <h:outputText value="Event Duration"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.duration}">

                        </h:outputText>
                    </p:column>


                    <p:column>
                        <f:facet name="header">
                            Update
                        </f:facet>
                        <h:commandButton action="updateEvent" type="image" image="../resources/images/table/action_edit.gif">

                            <f:setPropertyActionListener value="#{item}"
                                                         target="#{eventBean.event}" />
                        </h:commandButton>
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            Delete
                        </f:facet>

                        <p:commandLink ajax="false" onclick="{if (!confirm('Are you sure!')) return false}"
                                       update="pnl,grl"  action="Event" actionListener="#{eventBean.deleteEvent(item)}">
                            <p:graphicImage style="width: 20px" value="../resources/images/table/action_delete.gif"/>

                        </p:commandLink>


                    </p:column>


                </p:dataTable>


            </ui:define>


        </ui:composition>

    </body>
</html>
